package BlockUtils

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func GetBlock(block int64) string {

	url := "https://mainnet.helius-rpc.com/?api-key=a4b0ed9e-8646-4918-8b5c-4f5dade06e4b"

	jsonStr := fmt.Sprintf(`{
		"jsonrpc": "2.0",
		"id": "1",
		"method": "getBlock",
		"params": [%d,{"maxSupportedTransactionVersion": 0}]
	}`, block)

	jsonData := strings.NewReader(jsonStr)

	request, err := http.NewRequest("POST", url, jsonData)

	if err != nil {
		fmt.Printf("Error create Request：%v", err)
	}

	request.Header.Add("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(request)

	if err != nil {
		fmt.Printf("Error create Client：%v", err)
	}

	defer res.Body.Close()
	body, err := io.ReadAll(res.Body)

	if err != nil {
		fmt.Printf("Error create Client：%v", err)
	}

	//fmt.Println(res)
	//fmt.Println(string(body))

	return string(body)
}
